//
//  CateBigCell.m
//  zhongwulegou
//
//  Created by qianfeng on 15/9/18.
//  Copyright (c) 2015年 qianfeng. All rights reserved.
//

#import "CateBigCell.h"
#import "CateLittleCell.h"
#import "cateGoodsModel.h"
#import "collectionHeadView.h"
#import "UIImageView+AFNetworking.h"

@implementation CateBigCell

- (void)awakeFromNib {
    // Initialization code
    
    
    [_littleCollectionView registerNib:[UINib nibWithNibName:@"CateLittleCell" bundle:nil] forCellWithReuseIdentifier:@"CateLittleCell"];
    [_littleCollectionView registerNib:[UINib nibWithNibName:@"collectionHeadView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"collectionHeadView"];
}

#pragma mark -UICollectionViewDataSource
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _goodsArray.count;
}
//cell 复用
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CateLittleCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CateLittleCell" forIndexPath:indexPath];
    cateGoodsModel *model = self.goodsArray[indexPath.row];
    [cell.imgView setImageWithURL:[NSURL URLWithString:model.imageURL]];
    cell.nameLabel.text = model.goodName;
    return cell;
}


-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    //使cell 充满 collectionView
    return CGSizeMake(self.frame.size.width/3 , self.frame.size.width/3*1.2);
}
//返回段头的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
{
    return CGSizeMake(_littleCollectionView.frame.size.width, 30);
}

-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    UICollectionReusableView *reusableView = nil;
    
    if ([kind isEqualToString:UICollectionElementKindSectionHeader]) {
        
        collectionHeadView * header = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"collectionHeadView" forIndexPath:indexPath];
        header.nameLabel.text = self.gcName;
        reusableView = header;
        
        
        
        
    }
    
    return reusableView;
}
@end
